<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>供应商平台</title>
</head>
<body class="tob-wrap">
	<div th:replace="common/top"></div>
	<article class="container container-c9-maintenance clearfix">
		<div th:replace="common/left::c_side"></div>
		<section class="content">
			<h3 class="m-top-bar">
			</h3>

			<div class="m-table-sell">
				<table width="100%" summay="" cellpadding="0" cellspacing="0">
					<tr>
						<td class="td-left" width="50%">

							<div class="m-forms">
								<form id="form_personal" action="#" method="post" th:action="@{/maintance/CreateOrganization}" th:object="${purchaseOrganization}" th:method="post">
									<div style="color: red; text-align: center;">  
						            	<span th:text="${errorMsg}"></span>
									</div>
									<p>
										<label for="">Business ID : </label>
										 <select onchange="changPerple(this)" class="select select-w140" name="companyId" id="companyId">
											<option value="">请选择</option>
									   <option th:each="Company : ${tCompanyList}" th:value="${Company.id}" th:text="${Company.companyName}"></option>
										</select>
									</p>
									<p>
										<label for="">采购组织编号 : </label> <input class="input"
											type="text" placeholder="请输入" th:field="*{organizationNo}"/>
									</p>
									<p>
										<label for="">名称 : </label> <input class="input" type="text"
											placeholder="请输入" th:field="*{organizationName}"/>
									</p>
									<p>
										<label for="">负责人 : </label> <select
											class="select select-w140" name="userId" id="userId">
											<option value="">请选择</option>
											<option th:each="tPurchaseOrganization : ${tPurchaseOrganizationList}" th:value="${tPurchaseOrganization.tUser.id}" th:text="${tPurchaseOrganization.tUser.realName}"></option>
										</select>
									</p>
									<p class="p-address clearfix">
										<label for="">建议收货地址 : </label> 
										
										
										<!--<select class="select select-w140" name="provinceId" id="provinceId">
											<option value="">请选择</option>
											<option th:each="tPurchaseOrganization : ${tPurchaseOrganizationList}" th:value="${tPurchaseOrganization.tProvince.id}" th:text="${tPurchaseOrganization.tProvince.provinceName}"></option>
										</select>-->
								<select  class="select" onchange="changProvince(this)" name="provinceId" id="provinceId">
						              <option th:each="province : ${pList}" th:value="${province.id}" th:text="${province.provinceName}" th:if="${province.provinceName==tPurchaseOrganizationList[0].tProvince.provinceName}" selected = "selected"></option>
						        	  <option th:each="province : ${pList}" th:value="${province.id}" th:text="${province.provinceName}" th:if="${province.provinceName!=tPurchaseOrganizationList[0].tProvince.provinceName}"></option>
						        </select>
										
										
										 <span class="span-label"> 省 </span> <br /> 
										 <select class="select select-w140" name="cityId" id="cityId">
											<option value="">请选择</option>
									<option th:each="tPurchaseOrganization : ${tPurchaseOrganizationList}" th:value="${tPurchaseOrganization.tCity.id}" th:text="${tPurchaseOrganization.tCity.cityName}"></option>
										</select> <span class="span-label"> 市 </span> <br />
										<textarea class="textarea" name="address" id="address" cols="25" rows="2"></textarea>
									</p>
									<p class="btn-bar">
										<button class="btn btn-cyan" type="submit">保存</button>	
										<button class="btn btn-simple" onClick="javascript:backToSupplyerIndex();">取消</button>		
									</p>
									
								</form>	
							</div>
							
						</td>
						<td class="td-right" width="50%">
							<h4 th:text="'Business ID :  '+${tCompany.companyName}"></h4>
							<table class="table-in" width="100%" summay="" cellpadding="0"
								cellspacing="0">
								<thead>
									<th width="75">采购组织编号</th>
									<th>名称</th>
									<th>负责人</th>
									<th>省市</th>
									<th>收货地址</th>
								</thead>
								<tbody>
									<tr   th:each="tPurchaseOrganization : ${tPurchaseOrganizationList}">
										<td th:text="${tPurchaseOrganization.organizationNo}"></td>
										<td th:text="${tPurchaseOrganization.organizationName}"></td>
										<td th:text="${tPurchaseOrganization.tUser.realName}"></td>
										<td th:text="${tPurchaseOrganization.tProvince.provinceName}+${tPurchaseOrganization.tCity.cityName}"></td>
										<td th:text="${tPurchaseOrganization.address}">海淀区上地东路12号..</td>
									</tr>
								</tbody>
							</table>
						</td>
					</tr>
				</table>
			</div>
		</section>
	</article>
</body>
<script>
          function changPerple(obj){
        	    var companyId = obj.options[obj.selectedIndex].value;
           	    $.ajax({
       		        type:"GET",
       		        contentType: 'application/json', 
       		        url:"/api/" + companyId + "/user",  
       		        success: function(response){	
       		        	var html = '';
       		        	$.each(response, function(i, item) {
       		        		html = html + '<option value="' + item.id + '">' + item.realName + '</option>';
       		    	 	})
       		    	 	$("#userId").html(html);
       		        }
       	    	});
          }
</script>    

<script>
          function changProvince(obj){
        	    var provinceId = obj.options[obj.selectedIndex].value;
					debugger;
           	    $.ajax({
       		        type:"GET",
       		        contentType: 'application/json', 
       		        url:"/api/" + provinceId + "/city",        
       		        success: function(response){	
       		        	debugger;
       		        	var html = '';
       		        	$.each(response, function(i, item) {
       		        		html = html + '<option value="' + item.id + '">' + item.cityName + '</option>';
       		    	 	})
       		    	 	$("#cityId").html(html);
       		        }
       	    	});
          }
</script>     

<script data-main="../js/page/b1_supplier"
	src="../lib/requirejs/require.js"></script>
	<script type="text/javascript" src="../lib/jquery/dist/jquery.js"></script>
	<script type="text/javascript" src="../js/page/b2_order.js"></script>
</html>